package com.gary.test.ws.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;

public class PasswordHandler implements CallbackHandler {
	
	private static final Map<String,String> pwMockDB = new HashMap<String,String>();
	static{
		pwMockDB.put("admin", "admin123");
	}
	public void handle(Callback[] callbacks) throws IOException,
			UnsupportedCallbackException {
		WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
		String id = callback.getIdentifier();
		callback.setPassword(pwMockDB.get(id));
	}

}
